package com.ruoyi.security.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.security.domain.AfRule;
import com.ruoyi.security.service.IAfRuleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 法规制度Controller
 *
 * @author cjie
 * @date 2021-07-24
 */
@Api(tags = " 法规制度")
@RestController
@RequestMapping("/afRule")
public class AfRuleController extends BaseController {
    @Autowired
    private IAfRuleService afRuleService;

    /**
     * 查询法规制度列表
     */
    @ApiOperation(value="查询法规制度列表", notes="查询法规制度列表")
    @PreAuthorize(hasPermi = "security:afRule:list")
    @GetMapping("/list")
    public TableDataInfo list(AfRule afRule) {
        startPage();
        List<AfRule> list = afRuleService.selectAfRuleList(afRule);
        return getDataTable(list);
    }

    /**
     * 导出法规制度列表
     */
    @ApiOperation(value="导出法规制度列表", notes="导出法规制度列表")
    @PreAuthorize(hasPermi = "security:afRule:export")
    @Log(title = "法规制度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfRule afRule) throws IOException {
        List<AfRule> list = afRuleService.selectAfRuleList(afRule);
        ExcelUtil<AfRule> util = new ExcelUtil<AfRule>(AfRule.class);
        util.exportExcel(response, list, "法规制度数据");
    }
    /**
     * 获取法规制度详细信息
     */
    @ApiOperation(value="获取法规制度详细信息", notes="获取法规制度详细信息")
    @PreAuthorize(hasPermi = "security:afRule:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afRuleService.selectAfRuleById(id));
    }

    /**
     * 新增法规制度
     */
    @ApiOperation(value="新增法规制度", notes="新增法规制度")
    @PreAuthorize(hasPermi = "security:afRule:add")
    @Log(title = "法规制度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfRule afRule) {
        return toAjax(afRuleService.insertAfRule(afRule));
    }

    /**
     * 修改法规制度
     */
    @ApiOperation(value="修改法规制度", notes="修改法规制度")
    @PreAuthorize(hasPermi = "security:afRule:edit")
    @Log(title = "法规制度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfRule afRule) {
        return toAjax(afRuleService.updateAfRule(afRule));
    }

    /**
     * 删除法规制度
     */
    @ApiOperation(value="删除法规制度", notes="删除法规制度")
    @ApiImplicitParam(name = "ids", value = "法规制度ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afRule:remove")
    @Log(title = "法规制度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afRuleService.deleteAfRuleByIds(ids));
    }
}
